mui.plusReady(function() {
	var user = app.getState();
	var uid = user.user_id;
	var myWallet = ethscan.getWallet('eth');
	var self = plus.webview.currentWebview();
	var type = self.type;
	//console.log(type);
	mui.init({
		pullRefresh: {
			container: '#pullrefresh',
			up: {
				contentrefresh: '',
				callback: pullupRefresh
			}
		}
	});

	var count = 0;
	/**
	 * 上拉加载具体业务实现
	 */
	var page = 0;
	var p = 0;

	function pullupRefresh() {
		//setTimeout(function() {
		mui('#pullrefresh').pullRefresh().endPullupToRefresh((count++ > 10));
		var table = document.body.querySelector('.mui-table-view');
		var cells = document.body.querySelectorAll('.mui-table-view-cell');
		count = cells.length;
		var size = 20;
		if(count == 0 || count < size) {
			page = 0;
		} else {
			page = Math.ceil(count / size);
		}
		console.log(page);
		if(page + 1 == p) {
			return;
		}
		p = page + 1;
		var url = weburl + 'home/ChatApi/getlist?status=1&page=' + p + '&size=' + size + '&type=' + type;
		console.log(url);
		mui.getJSON(url, function(res) {
			//console.log(res);
			if(res.length > 0) {
				document.getElementById('area').innerHTML = document.getElementById('area').innerHTML + template("tpl", {
					data: res
				});
			} else {
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
			}
		});
		/*
		var str = '';
		for(var i = cells.length, len = i + 20; i < len; i++) {
			str += '<li class="mui-table-view-cell"><a class="mui-navigate-right">Item ' + (i + 1) + '</a></li>';
			table.appendChild(str);
		}*/
		//}, 500);
	}
	var ii = 0;
	mui("#area").on('tap', '.compay', function() {
		ii++;
		if(ii > 1) {
			return;
		}
		//console.log(this.id);
		var me = this;
		var url = weburl + 'home/ChatApi/getone?&id=' + this.id;
		//doc.getElementById(this.id).disabled = true;
		//console.log(url);
		mui.getJSON(url, function(res) {
			//console.log(JSON.stringify(res));
			if(!res || !res.status || res.status != 1) {
				mui.alert("已审核或数据不存在！");
				return;
			} else {
				//冲链减币加钱
				if(res.fromtype == 1) {
					mui.post(weburl + 'home/ChatApi/chonglianck', res, function(rt) {
						mui.alert(rt.msg);
						ii = 0;
						if(!rt || !rt.status || rt.status < 1) {
							return;
						} else {
							me.parentNode.removeChild(me);

						}
					});
				} else {
					//提链加币减钱
					var coindata = ethscan.getDefCoin();
					var pay = '' + res.money * res.rate;
					var type = coindata.name;
					var message = '用户' + res.user_name +
						'\r\n领导人:  ' + res.leader +
						'\r\n\r\n        提取' + type + ':  ' + (+res.money) +
						'\r\n实际支付' + type + ':  ' + pay +
						'\r\n';

					//console.log(res.wallet_addr);
					//return;
					mui.confirm(message, '提链审核', ['确认', '取消'], function(result) {

						if(result.index === 1) {
							ii = 0;
							return;
						}
						ethscan.payToAddrEth(res.wallet_addr, coindata['ctype'], coindata, pay, function(obj, addr) {
							console.log(JSON.stringify(obj));
							ii = 0;
							if(!obj || !obj.hash) {
								mui.alert('付款失败！');
							} else {
								document.getElementById('status' + res.id).innerHTML = "已审核";
								me.parentNode.removeChild(me);
								res.hash = obj.hash;
								mui.post(weburl + 'home/ChatApi/tilianck', res, function(rt) {
									console.log(JSON.stringify(rt))
								});
								mui.toast('付款成功！');
							}
						}, function(err) {
							console.log(JSON.stringify(err));
							mui.alert('付款失败！');
						});
					});
				}

			}
		});
	});
	if(mui.os.plus) {
		setTimeout(function() {
			mui('#pullrefresh').pullRefresh().pullupLoading();
		}, 1000);
	} else {
		mui('#pullrefresh').pullRefresh().pullupLoading();
	}
});